﻿Imports System.Text
Imports System.IO.Ports

Public Class Form1

    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim data As String = Me.Label1.Text
        Dim tmp As Integer
        Dim hbyte As String
        Dim lbyte As String
        Dim datasend() As Byte

        tmp = 65536 + Asc("班")
        lbyte = Hex(tmp Mod 256)
        hbyte = Hex(tmp \ 256)

        ReDim datasend(2)
        datasend(0) = Val("&H" & hbyte)
        datasend(1) = Val("&H" & lbyte)

        '打开串口
        If Me.SerialPort1.IsOpen Then
            Me.SerialPort1.Close()
        End If
        Me.SerialPort1.Open()

        '发送数据
        'Me.SerialPort1.RtsEnable = True
        'Call Sleep(10)

        'SerialPort1.Write(hbyte)
        'SerialPort1.Write(lbyte)

        SerialPort1.Write(datasend, 0, 2)

        'Call Sleep(10)
        'Me.SerialPort1.RtsEnable = False


        Me.Label1.Text = Hex(65536 + Asc("班班班"))
    End Sub




End Class